<template>
  <section class="my-flea">
    <div
      class="task"
      @click="routerTo(item.productId)"
      v-for="item in list"
      :key="item.productId"
    >
      <div class="top flex flex-between">
        <div class="left flex">
          <img :src="item.frontImgUrl">
          <div class="flex-col flex-between content-flex">
            <div class="title">{{item.productName}}</div>
            <div>
              <div class="status status-tag">{{item.displaceGoodsClass == 1?'置换':'出售'}}</div>
              <div class="status status-tag">{{typeOption[item.quality]}}</div>
            </div>
            <div class="price">￥{{item.price}}</div>
          </div>
        </div>
        <div class="right flex-col flex-bottom">
          <div class="status">{{item.productStatus == 1 ? (item.displaceGoodsClass == 1?'置换中':'出售中') : statusOption[item.productStatus]}}</div>
          <div class="mt15 num">X{{item.nums}}</div>
        </div>
      </div>
      <div class="bottom flex flex-main-end">
        <button
          v-if="item.productStatus == 1"
          @click.stop="soldOut(item.productId,1)"
        >下架</button>
        <button
          v-if="item.productStatus == 2 || item.productStatus == 0"
          @click.stop="soldOut(item.productId,2)"
        >删除</button>
      </div>
    </div>
    <div class="footer">

      <button
        class="release-task"
        @click="routerTo(0)"
      >
        <van-icon
          custom-class="van-icon"
          name="plus"
          color="white"
        /><span>发布物品</span></button>
    </div>
  </section>
</template>
<script>
export default {
  data() {
    return {
      list: '',
      statusOption: {
        2: '完成',
        0: '下架'
      },
      typeOption: {
        1: '全新',
        2: '九成新',
        3: '八成新',
        4: '七成新',
        5: '六成新',
        6: '五成新'
      }
    };
  },
  onShow() {
    this.myDisplaceGoods();
  },
  methods: {
    routerTo(id) {
      if (id == 0) {
        wx.navigateTo({ url: "../releaseitems/main" });
      } else {
        wx.navigateTo({ url: "../fleadetail/main?id=" + id });
      }
    },
    myDisplaceGoods() {
      this.$api.myDisplaceGoods().then(res => {
        this.list = res.data.list;
      })
    },
    // 1.下架 2.删除
    soldOut(productId, type) {
      const _this = this;
      if (type == 1) {
        wx.showModal({
          title: '下架',
          content: '您要下架此商品？',
          success(res) {
            if (res.confirm) {
              _this.$api.soldOut({ productId, type }).then(res => {
                _this.myDisplaceGoods();
              })
            } else if (res.cancel) {
            }
          }
        })
      } else if (type == 2) {
        wx.showModal({
          title: '删除',
          content: '您确定要删除此商品？',
          success(res) {
            if (res.confirm) {
              _this.$api.soldOut({ productId, type }).then(res => {
                _this.myDisplaceGoods();
              })
            } else if (res.cancel) {
            }
          }
        })
      }


    }
  }
};
</script>
<style lang="scss" scoped>
.my-flea {
  padding-bottom: 60px;
  .task {
    background: white;
    padding: 25px 15px;
    margin: 15px;
    background: rgba(255, 255, 255, 1);
    border-radius: 4px;
    .top {
      padding-bottom: 15px;
      .left {
        img {
          width: 70px;
          height: 70px;
          border-radius: 2px;
          margin-right: 10px;
        }
        .titile {
          font-size: 15px;
          font-family: PingFang;
          font-weight: 500;
          color: rgba(46, 46, 46, 1);
          line-height: 21px;
        }
        .status {
          font-size: 12px;
          font-family: PingFang;
          font-weight: 500;
          color: rgba(193, 196, 201, 1);
          width: 45px;
          height: 18px;
          line-height: 18px;
          text-align: center;
          background: rgba(247, 247, 247, 1);
          border-radius: 2px;
        }
        .price {
          font-size: 15px;
          font-family: PingFang;
          font-weight: 400;
          color: rgba(255, 156, 0, 1);
          line-height: 22px;
        }
      }
      .right {
        width: 100px;
        .status {
          padding: 3px 6px;
          border: 1px solid rgba(59, 184, 253, 1);
          border-radius: 2px;
          font-size: 12px;
          font-family: PingFang;
          font-weight: 500;
          color: rgba(59, 184, 253, 1);
        }
        .num {
          font-size: 15px;
          font-family: PingFang;
          font-weight: 500;
          color: rgba(193, 196, 201, 1);
        }
      }
    }
    .bottom {
      padding-top: 15px;
      border-top: 1px solid #f7f7f7;
      button {
        width: 50px;
        height: 24px;
        line-height: 24px;
        border: 0.5px solid rgba(193, 196, 201, 1);
        border-radius: 5px;
        padding: 0;
        margin: 0;
        margin-left: 30px;
        font-size: 12px;
        font-family: PingFang;
        font-weight: 500;
        color: rgba(193, 196, 201, 1);
      }
    }
  }
  .footer {
    width: 100%;
    background: #f7f7f7;
    height: 60px;
    position: fixed;
    left: 0;
    bottom: 0;
    z-index: 99;
    .release-task {
      width: 345px;
      background: rgba(59, 184, 253, 1);
      color: white;
      border-radius: 5px;
      padding: 0;
      text-align: center;
    }
  }
}
.content-flex {
  flex: 1;
}
.status-tag {
  display: inline-block;
  margin-right: 5px;
}
</style>
<style lang="scss">
page {
  background: #f7f7f7;
}
</style>